package com.geostart.constructionland.system.controller;


import com.alibaba.fastjson.JSONObject;
import com.geostar.constructionland.common.entity.response.ExtJsAjaxResponse;
import com.geostar.constructionland.common.entity.statistics.StatisticsProfile;
import com.geostar.constructionland.common.entity.statistics.UnifiedDataQueryConfig;
import com.geostar.constructionland.common.global.AnalyseType;
import com.geostart.constructionland.system.service.DataQueryConfigFeignClient;
import com.geostart.constructionland.system.service.StatisticsProfileFeignClient;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;

/**
 * @Author makoto_zhu
 * @Date 2020-11-06 03:44:40
 * @Description 增加数据查询页面
 **/
@Slf4j
@Controller
@Api("统计配置分析页面")
public class StatisticsController {

    @Autowired
    private StatisticsProfileFeignClient statisticsProfileFeignClient;

    @Autowired
    private DataQueryConfigFeignClient dataQueryConfigFeignClient;

    @GetMapping(path = "/statistics/profile")
    public String profile() {
        return "profile/statistics_profile";
    }

    // 数据查询页面接口
    @GetMapping(path = "/query/profile")
    public String dataQueryprofile() {
        return "profile/data_query";
    }

    @ResponseBody
    @PostMapping(path = "/statisticsProfile/list")
    public ExtJsAjaxResponse list(
            @RequestParam(value = "page") int pageNo,
            @RequestParam(value = "limit") int pageNum,
            @RequestParam(required = false) String query_param_statistics_name) {
        return statisticsProfileFeignClient.list(pageNo, pageNum, query_param_statistics_name);
    }

    @ResponseBody
    @PostMapping(path = "/statisticsProfile/delete")
    public ExtJsAjaxResponse delete(String id) {
        return statisticsProfileFeignClient.delete(id);
    }

    @ResponseBody
    @PostMapping(path = "/statisticsProfile/add")
    public ExtJsAjaxResponse add(@Valid StatisticsProfile statisticsProfile) {
        return statisticsProfileFeignClient.add(statisticsProfile);
    }

    @ResponseBody
    @PostMapping(path = "/statisticsProfile/update")
    public ExtJsAjaxResponse create(@Valid StatisticsProfile statisticsProfile) {
        return statisticsProfileFeignClient.update(statisticsProfile);
    }

    @ResponseBody
    @PostMapping(path = "/statisticsProfile/executeStatement")
    public ExtJsAjaxResponse<String> executeStatement(@RequestParam String uniqueTaskId, @RequestParam String ywid) {
        return statisticsProfileFeignClient.getStatistic(uniqueTaskId, ywid);
    }

    @ResponseBody
    @PostMapping(path = "/enum/getAnalysisTypeValues")
    public String getAnalysisTypeValues() {
        return JSONObject.toJSONString(AnalyseType.getEnumList());
    }


    // 数据查询页面接口
    @GetMapping(path = "/udp/profile")
    public String unfiedDataQueryprofile() {
        return "profile/udq_data_query";
    }

    @ResponseBody
    @PostMapping(path = "/statistics/list")
    public ExtJsAjaxResponse unifiedQueryConfiglist(
            @RequestParam(value = "page") int pageNo,
            @RequestParam(value = "limit") int pageNum,
            String query_param_statistics_id) {
        return dataQueryConfigFeignClient.udqList(pageNo, pageNum, query_param_statistics_id);
    }

    @ResponseBody
    @PostMapping(path = "/statistics/delete")
    public ExtJsAjaxResponse unifiedQueryConfigConfigFeignClient(String id) {
        return dataQueryConfigFeignClient.udqDelete(id);
    }

    @ResponseBody
    @PostMapping(path = "/statistics/add")
    public ExtJsAjaxResponse unifiedQueryConfigConfigadd(@Valid UnifiedDataQueryConfig dataQueryConfig) {
        return dataQueryConfigFeignClient.udqAdd(dataQueryConfig);
    }

    @ResponseBody
    @PostMapping(path = "/statistics/update")
    public ExtJsAjaxResponse unifiedQueryConfigConfigcreate(@Valid UnifiedDataQueryConfig dataQueryConfig) {
        return dataQueryConfigFeignClient.udqUpdate(dataQueryConfig);
    }


    @ResponseBody
    @PostMapping(path = "/statistics/query")
    public ExtJsAjaxResponse unifiedQueryConfigData(String uniqueQueryId, String params) {
        return dataQueryConfigFeignClient.udqQuery(uniqueQueryId, params);
    }
}
